//
//  ESFeedBackViewController.m
//  EasyStyle
//
//  Created by FK on 16/6/1.
//  Copyright © 2016年 FK. All rights reserved.
//

#import "ESFeedBackViewController.h"
#import "ESWeChatLoadingView.h"

@interface ESFeedBackViewController ()<UIScrollViewDelegate,UITextViewDelegate,UIAlertViewDelegate>
@property (nonatomic, strong)UIScrollView           *mainScrollView;
@end

@implementation ESFeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupRootView];
    
    [self setupMainScrollView:self.mainScrollView.frame];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -- 布局相关
- (void)setupRootView
{
    self.view.backgroundColor = [UIColor colorWithHex:@"f5f6f9"];
    
//    NSInteger startX = 12;
    NSInteger startY = 0;
//    NSInteger endX = self.view.frame.size.width - 12;
//    NSInteger endY = self.view.frame.size.height;
//    
    
    WS(weakSelf);
    self.navigationController.navigationBarHidden = YES;
    [self addCustomNavigationBarWithStyle:DefaultStyle customColor:[UIColor colorWithHex:@"3ec5dc"]];
    
    [self.sgCustomNavigationBar showBackButtonWithActionBlock:^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    [self.sgCustomNavigationBar setTitle:@"意见反馈"];
    self.sgCustomNavigationBar.titleLabel.textColor = [UIColor whiteColor];
    
    // 发送Btn
    UIButton *sendButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 88, 44)];
    sendButton.backgroundColor = [UIColor clearColor];
    [sendButton setTitle:@"发送" forState:UIControlStateNormal];
    [sendButton addTarget:self action:@selector(sendFeedbackMsg:) forControlEvents:UIControlEventTouchUpInside];
    [self.sgCustomNavigationBar setRightBarButtonView:sendButton];
    
    startY += self.sgCustomNavigationBar.height;
    
    
    ///初始化mainScrollView
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, startY, self.view.width, self.view.height-startY)];
    self.mainScrollView.clipsToBounds = NO;
    self.mainScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.mainScrollView.backgroundColor = [UIColor colorWithHex:@"f5f6f9"];
    self.mainScrollView.alpha = 1;
    self.mainScrollView.bounces = YES;
    self.mainScrollView.showsHorizontalScrollIndicator = NO;
    self.mainScrollView.showsVerticalScrollIndicator = NO;
    self.mainScrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.mainScrollView.delegate = self;
    [self.view addSubview:self.mainScrollView];
    
    [self.view bringSubviewToFront:self.sgCustomNavigationBar];
}

- (void)setupMainScrollView:(CGRect)parentFrame
{

    NSInteger startX = 12;
    NSInteger startY = 0;
    NSInteger endX = parentFrame.size.width - 12;
    NSInteger endY = parentFrame.size.height;

    startY += 10;
    UILabel *msgTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(startX, startY, endX - startX, 20)];
    msgTitleLabel.backgroundColor = [UIColor clearColor];
    msgTitleLabel.textColor = [UIColor colorWithHex:@"656565"];
    msgTitleLabel.textAlignment = NSTextAlignmentLeft;
    msgTitleLabel.text = @"反馈描述（必填）";
    msgTitleLabel.font = ESFontWithSize(15);
    [self.mainScrollView addSubview:msgTitleLabel];
    startY += msgTitleLabel.height;
    
    
    startY += 5;
    UITextView *msgTextView = [[UITextView alloc]initWithFrame:CGRectMake(startX, startY, endX - startX, 150)];
    msgTextView.layer.cornerRadius = 4.0f;
    msgTextView.backgroundColor = [UIColor whiteColor] ;
    msgTextView.font = [UIFont systemFontOfSize:14];
    msgTextView.delegate = self ;
//    设置此UITextView为第一响应者，即默认打开键盘。
    [msgTextView becomeFirstResponder];
//    当UITextView中含有文字时，系统默认将光标定位到最后的位置，下面的语句将光标定位到首位置。
    msgTextView.selectedRange = NSMakeRange(0,0);
    [self.mainScrollView addSubview:msgTextView];
    startY += msgTextView.height;
    
    startY += 15;
    UILabel *contactTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(startX, startY, endX - startX, 20)];
    contactTitleLabel.backgroundColor = [UIColor clearColor];
    contactTitleLabel.textColor = [UIColor colorWithHex:@"656565"];
    contactTitleLabel.textAlignment = NSTextAlignmentLeft;
    contactTitleLabel.text = @"联系方式";
    contactTitleLabel.font = ESFontWithSize(15);
    [self.mainScrollView addSubview:contactTitleLabel];
    startY += contactTitleLabel.height;
    
    startY += 5;
    UITextField *contactMethodTxt = [[UITextField alloc]initWithFrame:CGRectMake(startX, startY, endX - startX, 30)];
    contactMethodTxt.layer.cornerRadius = 4.0f;
    contactMethodTxt.backgroundColor = [UIColor whiteColor];
    contactMethodTxt.font = [UIFont systemFontOfSize:14];
    [self.mainScrollView addSubview:contactMethodTxt];
    startY += contactMethodTxt.height;
    
    startY += 10;
    UILabel *thsLabel = [[UILabel alloc]initWithFrame:CGRectMake(startX, startY, endX - startX, 20)];
    thsLabel.backgroundColor = [UIColor clearColor];
    thsLabel.textColor = [UIColor colorWithHex:@"bcbcbe"];
    thsLabel.textAlignment = NSTextAlignmentCenter;
    thsLabel.text = @"感谢您的宝贵意见";
    thsLabel.font = ESFontWithSize(13);
    [self.mainScrollView addSubview:thsLabel];
    startY += thsLabel.height;
    
    
    startY += startY + 40;
    

    [self.mainScrollView setContentSize:CGSizeMake(parentFrame.size.width, startY)];
    

}

#pragma mark -- 事件函数
- (void)sendFeedbackMsg:(UIButton *)sender
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"发送成功" message:@"感谢你提供的宝贵意见" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
    alert.tag = 1001;
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 1001) {
        if (buttonIndex == 0) {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}


@end
